<template>
  <div class="enrollment-statistics">
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/" class="breadcrumb">
      <el-breadcrumb-item :to="{ path: '/dashboard' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>统计报表</el-breadcrumb-item>
      <el-breadcrumb-item>报名统计</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 统计概览卡片 -->
    <el-row :gutter="20" class="overview-cards">
      <el-col :span="6">
        <el-card class="stat-card">
          <div class="stat-item">
            <div class="stat-icon" style="background-color: #409eff;">
              <el-icon><User /></el-icon>
            </div>
            <div class="stat-content">
              <div class="stat-value">{{ overviewData.totalEnrollments || 0 }}</div>
              <div class="stat-label">总报名人数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="stat-card">
          <div class="stat-item">
            <div class="stat-icon" style="background-color: #67c23a;">
              <el-icon><Trophy /></el-icon>
            </div>
            <div class="stat-content">
              <div class="stat-value">{{ overviewData.projectCount || 0 }}</div>
              <div class="stat-label">报名项目数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="stat-card">
          <div class="stat-item">
            <div class="stat-icon" style="background-color: #e6a23c;">
              <el-icon><OfficeBuilding /></el-icon>
            </div>
            <div class="stat-content">
              <div class="stat-value">{{ overviewData.collegeCount || 0 }}</div>
              <div class="stat-label">参与学院数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="stat-card">
          <div class="stat-item">
            <div class="stat-icon" style="background-color: #f56c6c;">
              <el-icon><TrendCharts /></el-icon>
            </div>
            <div class="stat-content">
              <div class="stat-value">{{ overviewData.todayEnrollments || 0 }}</div>
              <div class="stat-label">今日新增报名</div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 筛选和操作区域 -->
    <el-card class="filter-card">
      <div class="filter-header">
        <div class="left-actions">
          <el-button type="primary" icon="Refresh" @click="handleRefresh">
            刷新数据
          </el-button>
          <el-button type="success" icon="Download" @click="handleExport">
            导出报表
          </el-button>
        </div>
        <div class="right-filters">
          <el-select
            v-model="filterForm.timeRange"
            placeholder="选择时间范围"
            style="width: 150px; margin-right: 10px;"
            @change="handleTimeRangeChange"
          >
            <el-option label="最近7天" value="7days" />
            <el-option label="最近30天" value="30days" />
            <el-option label="最近90天" value="90days" />
            <el-option label="自定义" value="custom" />
          </el-select>
          <el-date-picker
            v-if="filterForm.timeRange === 'custom'"
            v-model="filterForm.dateRange"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            style="width: 240px; margin-right: 10px;"
            @change="handleDateRangeChange"
          />
        </div>
      </div>
    </el-card>

    <!-- 图表区域 -->
    <el-row :gutter="20" class="chart-row">
      <!-- 报名趋势图 -->
      <el-col :span="12">
        <el-card class="chart-card">
          <template #header>
            <div class="card-header">
              <span>报名趋势分析</span>
              <el-radio-group v-model="trendChartType" size="small">
                <el-radio-button label="day">按日</el-radio-button>
                <el-radio-button label="week">按周</el-radio-button>
                <el-radio-button label="month">按月</el-radio-button>
              </el-radio-group>
            </div>
          </template>
          <div ref="trendChart" class="chart-container"></div>
        </el-card>
      </el-col>

      <!-- 项目报名分布 -->
      <el-col :span="12">
        <el-card class="chart-card">
          <template #header>
            <div class="card-header">
              <span>项目报名分布</span>
              <el-select v-model="projectChartType" size="small" style="width: 120px;">
                <el-option label="饼图" value="pie" />
                <el-option label="柱状图" value="bar" />
              </el-select>
            </div>
          </template>
          <div ref="projectChart" class="chart-container"></div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 学院报名统计和排行榜 -->
    <el-row :gutter="20" class="chart-row">
      <!-- 学院报名分布 -->
      <el-col :span="14">
        <el-card class="chart-card">
          <template #header>
            <div class="card-header">
              <span>学院报名分布</span>
              <el-radio-group v-model="collegeChartType" size="small">
                <el-radio-button label="college">按学院</el-radio-button>
                <el-radio-button label="class">按班级</el-radio-button>
              </el-radio-group>
            </div>
          </template>
          <div ref="collegeChart" class="chart-container"></div>
        </el-card>
      </el-col>

      <!-- 报名排行榜 -->
      <el-col :span="10">
        <el-card class="ranking-card">
          <template #header>
            <span>报名排行榜</span>
          </template>
          <div class="ranking-tabs">
            <el-tabs v-model="activeRankingTab" @tab-change="handleRankingTabChange">
              <el-tab-pane label="学院排行" name="college">
                <div class="ranking-list">
                  <div
                    v-for="(item, index) in collegeRankingData"
                    :key="item.id"
                    class="ranking-item"
                    :class="{ 'top-three': index < 3 }"
                  >
                    <div class="rank-number" :class="`rank-${index + 1}`">
                      {{ index + 1 }}
                    </div>
                    <div class="rank-info">
                      <div class="rank-name">{{ item.name }}</div>
                      <div class="rank-count">{{ item.enrollmentCount }}人</div>
                    </div>
                    <div class="rank-progress">
                      <el-progress
                        :percentage="getRankingPercentage(item.enrollmentCount, collegeRankingData)"
                        :stroke-width="8"
                        :show-text="false"
                      />
                    </div>
                  </div>
                </div>
              </el-tab-pane>
              <el-tab-pane label="项目排行" name="project">
                <div class="ranking-list">
                  <div
                    v-for="(item, index) in projectRankingData"
                    :key="item.id"
                    class="ranking-item"
                    :class="{ 'top-three': index < 3 }"
                  >
                    <div class="rank-number" :class="`rank-${index + 1}`">
                      {{ index + 1 }}
                    </div>
                    <div class="rank-info">
                      <div class="rank-name">{{ item.name }}</div>
                      <div class="rank-count">{{ item.enrollmentCount }}人</div>
                    </div>
                    <div class="rank-progress">
                      <el-progress
                        :percentage="getRankingPercentage(item.enrollmentCount, projectRankingData)"
                        :stroke-width="8"
                        :show-text="false"
                      />
                    </div>
                  </div>
                </div>
              </el-tab-pane>
            </el-tabs>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 详细数据表格 -->
    <el-card class="table-card">
      <template #header>
        <div class="card-header">
          <span>报名详细数据</span>
          <div class="table-actions">
            <el-input
              v-model="searchKeyword"
              placeholder="搜索学院、班级或项目"
              style="width: 200px; margin-right: 10px;"
              clearable
              @clear="handleSearch"
              @keyup.enter="handleSearch"
            >
              <template #append>
                <el-button icon="Search" @click="handleSearch" />
              </template>
            </el-input>
            <el-button type="primary" icon="Download" @click="exportTableData">
              导出表格
            </el-button>
          </div>
        </div>
      </template>

      <el-table
        v-loading="tableLoading"
        :data="tableData"
        stripe
        style="width: 100%"
      >
        <el-table-column type="index" label="#" width="60" />
        <el-table-column prop="collegeName" label="学院" min-width="120" />
        <el-table-column prop="className" label="班级" min-width="120" />
        <el-table-column prop="projectName" label="项目名称" min-width="150" show-overflow-tooltip />
        <el-table-column prop="projectType" label="项目类型" width="100">
          <template #default="{ row }">
            <el-tag :type="row.projectType === '个人' ? 'primary' : 'success'">
              {{ row.projectType }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="enrollmentCount" label="报名人数" width="100" sortable />
        <el-table-column prop="maleCount" label="男生人数" width="100" />
        <el-table-column prop="femaleCount" label="女生人数" width="100" />
        <el-table-column prop="enrollmentRate" label="报名率" width="100">
          <template #default="{ row }">
            {{ (row.enrollmentRate * 100).toFixed(1) }}%
          </template>
        </el-table-column>
        <el-table-column prop="lastEnrollTime" label="最近报名时间" width="180" />
        <el-table-column label="操作" width="120" fixed="right">
          <template #default="{ row }">
            <el-button
              type="primary"
              size="small"
              icon="View"
              @click="handleViewDetail(row)"
            >
              详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div class="pagination-wrapper">
        <el-pagination
          v-model:current-page="pagination.currentPage"
          v-model:page-size="pagination.pageSize"
          :page-sizes="[10, 20, 50, 100]"
          :total="pagination.total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handlePageSizeChange"
          @current-change="handlePageChange"
        />
      </div>
    </el-card>

    <!-- 详情对话框 -->
    <el-dialog
      v-model="detailDialogVisible"
      title="报名详情"
      width="800px"
    >
      <div class="detail-content">
        <el-descriptions :column="2" border>
          <el-descriptions-item label="学院">{{ currentDetail.collegeName }}</el-descriptions-item>
          <el-descriptions-item label="班级">{{ currentDetail.className }}</el-descriptions-item>
          <el-descriptions-item label="项目名称">{{ currentDetail.projectName }}</el-descriptions-item>
          <el-descriptions-item label="项目类型">
            <el-tag :type="currentDetail.projectType === '个人' ? 'primary' : 'success'">
              {{ currentDetail.projectType }}
            </el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="报名人数">{{ currentDetail.enrollmentCount }}人</el-descriptions-item>
          <el-descriptions-item label="报名率">{{ (currentDetail.enrollmentRate * 100).toFixed(1) }}%</el-descriptions-item>
          <el-descriptions-item label="男生人数">{{ currentDetail.maleCount }}人</el-descriptions-item>
          <el-descriptions-item label="女生人数">{{ currentDetail.femaleCount }}人</el-descriptions-item>
          <el-descriptions-item label="首次报名时间">{{ currentDetail.firstEnrollTime }}</el-descriptions-item>
          <el-descriptions-item label="最近报名时间">{{ currentDetail.lastEnrollTime }}</el-descriptions-item>
        </el-descriptions>
      </div>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="detailDialogVisible = false">关闭</el-button>
          <el-button type="primary" @click="exportDetailData">导出详情</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { ref, reactive, onMounted, onUnmounted, nextTick, watch } from 'vue'
import { ElMessage } from 'element-plus'
import * as echarts from 'echarts'
import {
  getEnrollmentOverview,
  getEnrollmentByGroup,
  getEnrollmentTrendChart,
  getProjectDistributionChart,
  getMedalRankingChart,
  exportEnrollmentStats
} from '@/api/statistics'

export default {
  name: 'EnrollmentStatistics',
  setup() {
    // 响应式数据
    const loading = ref(false)
    const tableLoading = ref(false)
    const overviewData = reactive({
      totalEnrollments: 0,
      projectCount: 0,
      collegeCount: 0,
      todayEnrollments: 0
    })

    // 图表相关
    const trendChart = ref(null)
    const projectChart = ref(null)
    const collegeChart = ref(null)
    let trendChartInstance = null
    let projectChartInstance = null
    let collegeChartInstance = null

    // 图表类型
    const trendChartType = ref('day')
    const projectChartType = ref('pie')
    const collegeChartType = ref('college')

    // 筛选表单
    const filterForm = reactive({
      timeRange: '30days',
      dateRange: null
    })

    // 搜索关键词
    const searchKeyword = ref('')

    // 表格数据
    const tableData = ref([])
    const pagination = reactive({
      currentPage: 1,
      pageSize: 20,
      total: 0
    })

    // 排行榜数据
    const collegeRankingData = ref([])
    const projectRankingData = ref([])
    const activeRankingTab = ref('college')

    // 详情对话框
    const detailDialogVisible = ref(false)
    const currentDetail = ref({})

    // 生命周期钩子
    onMounted(() => {
      loadOverviewData()
      loadTrendChart()
      loadProjectChart()
      loadCollegeChart()
      loadRankingData()
      loadTableData()

      // 窗口大小变化时重新渲染图表
      window.addEventListener('resize', handleResize)
    })

    onUnmounted(() => {
      // 销毁图表实例
      if (trendChartInstance) {
        trendChartInstance.dispose()
      }
      if (projectChartInstance) {
        projectChartInstance.dispose()
      }
      if (collegeChartInstance) {
        collegeChartInstance.dispose()
      }
      window.removeEventListener('resize', handleResize)
    })

    // 加载概览数据
    const loadOverviewData = async () => {
      try {
        const response = await getEnrollmentOverview()
        if (response.code === 200) {
          Object.assign(overviewData, response.data)
        }
      } catch (error) {
        console.error('加载概览数据失败:', error)
      }
    }

    // 加载趋势图数据
    const loadTrendChart = async () => {
      try {
        const params = {
          timeRange: filterForm.timeRange === 'custom' ? 'custom' : filterForm.timeRange,
          startDate: filterForm.dateRange?.[0],
          endDate: filterForm.dateRange?.[1],
          groupBy: trendChartType.value
        }

        const response = await getEnrollmentTrendChart(params)
        if (response.code === 200) {
          renderTrendChart(response.data)
        }
      } catch (error) {
        console.error('加载趋势图数据失败:', error)
      }
    }

    // 渲染趋势图
    const renderTrendChart = (data) => {
      nextTick(() => {
        if (!trendChart.value) return

        if (trendChartInstance) {
          trendChartInstance.dispose()
        }

        trendChartInstance = echarts.init(trendChart.value)

        const option = {
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'cross'
            }
          },
          legend: {
            data: ['报名人数', '新增报名']
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },
          xAxis: {
            type: 'category',
            boundaryGap: false,
            data: data.dates || []
          },
          yAxis: {
            type: 'value'
          },
          series: [
            {
              name: '报名人数',
              type: 'line',
              smooth: true,
              data: data.cumulativeData || [],
              itemStyle: {
                color: '#409eff'
              }
            },
            {
              name: '新增报名',
              type: 'bar',
              data: data.dailyData || [],
              itemStyle: {
                color: '#67c23a'
              }
            }
          ]
        }

        trendChartInstance.setOption(option)
      })
    }

    // 加载项目分布图
    const loadProjectChart = async () => {
      try {
        const response = await getProjectDistributionChart({
          groupBy: 'category'
        })
        if (response.code === 200) {
          renderProjectChart(response.data)
        }
      } catch (error) {
        console.error('加载项目分布图失败:', error)
      }
    }

    // 渲染项目分布图
    const renderProjectChart = (data) => {
      nextTick(() => {
        if (!projectChart.value) return

        if (projectChartInstance) {
          projectChartInstance.dispose()
        }

        projectChartInstance = echarts.init(projectChart.value)

        const chartData = data.chartData || []
        const option = projectChartType.value === 'pie' ? {
          tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b}: {c} ({d}%)'
          },
          legend: {
            orient: 'vertical',
            left: 'left'
          },
          series: [
            {
              name: '项目分布',
              type: 'pie',
              radius: '50%',
              data: chartData,
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]
        } : {
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow'
            }
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },
          xAxis: {
            type: 'value'
          },
          yAxis: {
            type: 'category',
            data: chartData.map(item => item.name)
          },
          series: [
            {
              name: '报名人数',
              type: 'bar',
              data: chartData.map(item => item.value),
              itemStyle: {
                color: '#409eff'
              }
            }
          ]
        }

        projectChartInstance.setOption(option)
      })
    }

    // 加载学院分布图
    const loadCollegeChart = async () => {
      try {
        const params = {
          groupType: collegeChartType.value,
          limit: 10
        }

        const response = await getMedalRankingChart(params)
        if (response.code === 200) {
          renderCollegeChart(response.data)
        }
      } catch (error) {
        console.error('加载学院分布图失败:', error)
      }
    }

    // 渲染学院分布图
    const renderCollegeChart = (data) => {
      nextTick(() => {
        if (!collegeChart.value) return

        if (collegeChartInstance) {
          collegeChartInstance.dispose()
        }

        collegeChartInstance = echarts.init(collegeChart.value)

        const chartData = data.chartData || []
        const option = {
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow'
            }
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },
          xAxis: {
            type: 'category',
            data: chartData.map(item => item.name),
            axisLabel: {
              rotate: 45
            }
          },
          yAxis: {
            type: 'value'
          },
          series: [
            {
              name: '报名人数',
              type: 'bar',
              data: chartData.map(item => item.value),
              itemStyle: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  { offset: 0, color: '#83bff6' },
                  { offset: 0.5, color: '#188df0' },
                  { offset: 1, color: '#188df0' }
                ])
              }
            }
          ]
        }

        collegeChartInstance.setOption(option)
      })
    }

    // 加载排行榜数据
    const loadRankingData = async () => {
      try {
        const params = {
          groupType: activeRankingTab.value === 'college' ? 'college' : 'project',
          limit: 10
        }

        const response = await getEnrollmentByGroup(params)
        if (response.code === 200) {
          if (activeRankingTab.value === 'college') {
            collegeRankingData.value = response.data || []
          } else {
            projectRankingData.value = response.data || []
          }
        }
      } catch (error) {
        console.error('加载排行榜数据失败:', error)
      }
    }

    // 加载表格数据
    const loadTableData = async () => {
      tableLoading.value = true
      try {
        // 模拟数据，实际应该调用API
        const mockData = [
          {
            id: 1,
            collegeName: '计算机学院',
            className: '软件工程21-1班',
            projectName: '100米短跑',
            projectType: '个人',
            enrollmentCount: 15,
            maleCount: 10,
            femaleCount: 5,
            enrollmentRate: 0.75,
            firstEnrollTime: '2024-03-01 09:00:00',
            lastEnrollTime: '2024-03-15 14:30:00'
          },
          {
            id: 2,
            collegeName: '计算机学院',
            className: '软件工程21-2班',
            projectName: '篮球比赛',
            projectType: '团体',
            enrollmentCount: 12,
            maleCount: 8,
            femaleCount: 4,
            enrollmentRate: 0.60,
            firstEnrollTime: '2024-03-02 10:00:00',
            lastEnrollTime: '2024-03-14 16:20:00'
          },
          {
            id: 3,
            collegeName: '电子工程学院',
            className: '通信工程21-1班',
            projectName: '乒乓球单打',
            projectType: '个人',
            enrollmentCount: 8,
            maleCount: 6,
            femaleCount: 2,
            enrollmentRate: 0.40,
            firstEnrollTime: '2024-03-03 11:00:00',
            lastEnrollTime: '2024-03-13 15:45:00'
          }
        ]

        tableData.value = mockData
        pagination.total = mockData.length
      } catch (error) {
        console.error('加载表格数据失败:', error)
        ElMessage.error('加载数据失败')
      } finally {
        tableLoading.value = false
      }
    }

    // 事件处理方法
    const handleRefresh = () => {
      loadOverviewData()
      loadTrendChart()
      loadProjectChart()
      loadCollegeChart()
      loadRankingData()
      loadTableData()
      ElMessage.success('数据已刷新')
    }

    const handleTimeRangeChange = (value) => {
      if (value !== 'custom') {
        filterForm.dateRange = null
      }
      loadTrendChart()
    }

    const handleDateRangeChange = () => {
      loadTrendChart()
    }

    const handleRankingTabChange = (tabName) => {
      activeRankingTab.value = tabName
      loadRankingData()
    }

    const handleSearch = () => {
      pagination.currentPage = 1
      loadTableData()
    }

    const handlePageChange = (page) => {
      pagination.currentPage = page
      loadTableData()
    }

    const handlePageSizeChange = (size) => {
      pagination.pageSize = size
      loadTableData()
    }

    const handleViewDetail = (row) => {
      currentDetail.value = { ...row }
      detailDialogVisible.value = true
    }

    // 导出功能
    const handleExport = async () => {
      try {
        const params = {
          format: 'excel',
          filters: {
            timeRange: filterForm.timeRange,
            dateRange: filterForm.dateRange,
            keyword: searchKeyword.value
          }
        }

        const response = await exportEnrollmentStats(params)

        // 创建下载链接
        const blob = new Blob([response], {
          type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
        })
        const url = window.URL.createObjectURL(blob)
        const link = document.createElement('a')
        link.href = url
        link.download = `报名统计报表_${new Date().toLocaleDateString()}.xlsx`
        link.click()
        window.URL.revokeObjectURL(url)

        ElMessage.success('报表导出成功')
      } catch (error) {
        console.error('导出报表失败:', error)
        ElMessage.error('导出报表失败')
      }
    }

    const exportTableData = () => {
      ElMessage.info('表格导出功能开发中...')
    }

    const exportDetailData = () => {
      ElMessage.info('详情导出功能开发中...')
    }

    // 图表类型变化处理
    const handleTrendChartTypeChange = () => {
      loadTrendChart()
    }

    const handleProjectChartTypeChange = () => {
      loadProjectChart()
    }

    const handleCollegeChartTypeChange = () => {
      loadCollegeChart()
    }

    // 工具方法
    const getRankingPercentage = (value, data) => {
      if (!data.length) return 0
      const max = Math.max(...data.map(item => item.enrollmentCount))
      return Math.round((value / max) * 100)
    }

    const handleResize = () => {
      if (trendChartInstance) {
        trendChartInstance.resize()
      }
      if (projectChartInstance) {
        projectChartInstance.resize()
      }
      if (collegeChartInstance) {
        collegeChartInstance.resize()
      }
    }

    // 监听图表类型变化
    const unwatchTrendType = ref(null)
    const unwatchProjectType = ref(null)
    const unwatchCollegeType = ref(null)

    onMounted(() => {
      unwatchTrendType.value = watch(trendChartType, handleTrendChartTypeChange)
      unwatchProjectType.value = watch(projectChartType, handleProjectChartTypeChange)
      unwatchCollegeType.value = watch(collegeChartType, handleCollegeChartTypeChange)
    })

    onUnmounted(() => {
      if (unwatchTrendType.value) {
        unwatchTrendType.value()
      }
      if (unwatchProjectType.value) {
        unwatchProjectType.value()
      }
      if (unwatchCollegeType.value) {
        unwatchCollegeType.value()
      }
    })

    return {
      // 响应式数据
      loading,
      tableLoading,
      overviewData,
      filterForm,
      searchKeyword,
      tableData,
      pagination,
      collegeRankingData,
      projectRankingData,
      activeRankingTab,
      detailDialogVisible,
      currentDetail,
      trendChartType,
      projectChartType,
      collegeChartType,

      // 图表引用
      trendChart,
      projectChart,
      collegeChart,

      // 方法
      handleRefresh,
      handleTimeRangeChange,
      handleDateRangeChange,
      handleRankingTabChange,
      handleSearch,
      handlePageChange,
      handlePageSizeChange,
      handleViewDetail,
      handleExport,
      exportTableData,
      exportDetailData,
      getRankingPercentage
    }
  }
}
</script>

<style lang="scss" scoped>
.enrollment-statistics {
  padding: 20px;

  .breadcrumb {
    margin-bottom: 20px;
  }

  // 概览卡片样式
  .overview-cards {
    margin-bottom: 20px;

    .stat-card {
      .stat-item {
        display: flex;
        align-items: center;

        .stat-icon {
          width: 60px;
          height: 60px;
          border-radius: 50%;
          display: flex;
          align-items: center;
          justify-content: center;
          margin-right: 15px;

          .el-icon {
            font-size: 28px;
            color: white;
          }
        }

        .stat-content {
          flex: 1;

          .stat-value {
            font-size: 28px;
            font-weight: bold;
            color: #303133;
            line-height: 1;
          }

          .stat-label {
            font-size: 14px;
            color: #909399;
            margin-top: 5px;
          }
        }
      }
    }
  }

  // 筛选卡片样式
  .filter-card {
    margin-bottom: 20px;

    .filter-header {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .left-actions {
        display: flex;
        gap: 10px;
      }

      .right-filters {
        display: flex;
        align-items: center;
      }
    }
  }

  // 图表行样式
  .chart-row {
    margin-bottom: 20px;

    .chart-card,
    .ranking-card {
      height: 400px;

      .card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
      }

      .chart-container {
        height: 320px;
        width: 100%;
      }
    }

    .ranking-card {
      .ranking-tabs {
        height: 320px;
        overflow-y: auto;

        .ranking-list {
          .ranking-item {
            display: flex;
            align-items: center;
            padding: 10px 0;
            border-bottom: 1px solid #f0f0f0;

            &.top-three {
              background-color: #f9f9f9;
            }

            .rank-number {
              width: 30px;
              height: 30px;
              border-radius: 50%;
              display: flex;
              align-items: center;
              justify-content: center;
              font-weight: bold;
              margin-right: 10px;

              &.rank-1 {
                background-color: #ffd700;
                color: #333;
              }

              &.rank-2 {
                background-color: #c0c0c0;
                color: #333;
              }

              &.rank-3 {
                background-color: #cd7f32;
                color: #fff;
              }
            }

            .rank-info {
              flex: 1;

              .rank-name {
                font-weight: 500;
                margin-bottom: 2px;
              }

              .rank-count {
                font-size: 12px;
                color: #666;
              }
            }

            .rank-progress {
              width: 100px;
              margin-left: 10px;
            }
          }
        }
      }
    }
  }

  // 表格卡片样式
  .table-card {
    .card-header {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .table-actions {
        display: flex;
        align-items: center;
      }
    }

    .pagination-wrapper {
      display: flex;
      justify-content: center;
      margin-top: 20px;
    }
  }

  // 详情对话框样式
  .detail-content {
    .el-descriptions {
      margin-top: 20px;
    }
  }

  .dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
  }
}

// 响应式设计
@media (max-width: 1200px) {
  .enrollment-statistics {
    .overview-cards {
      .el-col {
        margin-bottom: 10px;
      }
    }

    .chart-row {
      .el-col {
        margin-bottom: 20px;
      }
    }
  }
}

@media (max-width: 768px) {
  .enrollment-statistics {
    padding: 10px;

    .filter-header {
      flex-direction: column;
      gap: 15px;

      .left-actions,
      .right-filters {
        width: 100%;
        justify-content: center;
      }
    }

    .chart-card,
    .ranking-card {
      height: auto;
      min-height: 300px;
    }

    .card-header {
      flex-direction: column;
      gap: 10px;
      align-items: flex-start;
    }

    .table-card {
      .card-header {
        flex-direction: column;
        gap: 15px;
        align-items: flex-start;

        .table-actions {
          width: 100%;
          justify-content: center;
        }
      }
    }
  }
}
</style>